set more off
graph drop _all

	forval p = 1(1)1000 { 
quietly {
			
	
			use Data/Estimation_sample.dta, clear
		
				gen nexis_buildings  = ROOFME/PROOFME
					
					
				gen roofratio = ROOFME/ROOFTI
				gen roofratiobuildings = roofratio*nexis_buildings
					
				gen roofrelativeIV = (roofratio*nexis_buildings/[moduleprice])/1000

		

					
					local seedp = 843403942 + `p'
					set seed `seedp'
					
					
					gen randu = round(runiform(0,27))
					
					forval x =1(1)7 {
					summ randu if _n==`x'
					local t= r(mean)
					replace SHCP_end = SHCP_end + `t' if `x'==1
					replace PFIT_starttime = PFIT_starttime + `t' if `x'==2
					replace PFIT_endtime = PFIT_endtime + `t'  if `x'==3
					replace SRES1_endtime = SRES1_endtime + `t'  if `x'==4
					replace SRES2_endtime = SRES2_endtime + `t' if `x' ==5
					replace SRES_TFIT_endtime = SRES_TFIT_endtime + `t' if `x' ==6
					replace FFIT_endtime = FFIT_endtime + `t' if `x' ==7
					}
					
					
				
				
				
				local length = 3
				 
			forval t = 0(1)`length' {
				gen event_after`t' =  SHCP_end ==`t' |  PFIT_starttime==`t' | PFIT_endtime==`t' | ///
				 SRES1_end ==`t' | SRES2_end==`t' | SRES_TFIT_endtime==`t' | FFIT_endtime==`t'
				 
				 
				 gen event_before`t' =  SHCP_end ==-`t'  | PFIT_starttime==-`t' | PFIT_endtime==-`t' | ///
				 SRES1_end ==-`t' | SRES2_end==-`t' | SRES_TFIT_endtime==-`t' | FFIT_endtime==-`t'
				
				gen event_after_new`t' = event_after`t'*cum
				gen event_before_new`t' = event_before`t'*cum
				
				gen event_after_high`t' = event_after`t'*roofrelativeIV
				gen event_before_high`t' = event_before`t'*roofrelativeIV
				
				drop event_after`t'
				drop event_before`t'
				
				
				
				}


			xi: xtivreg2 green_p event_before_new3 event_before_new2 event_before_new1 event_before_new0 ///
			event_after_new1  event_after_new2 event_after_new3   i.quarter   [aweight=NCustomer]  , fe cluster(postcode)


			

			eststo model`p'

			estimates save Analysis/placebo`p' , replace
			
			estimates drop  model`p'
			}
			}
			
